<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Selenium IDE Test</title>
    <link rel="stylesheet" type="text/css" href="chrome://selenium-ide/content/jsunit/css/jsUnitStyle.css">
		<script type="text/javascript" src="chrome://selenium-ide/content/selenium-core/lib/prototype.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/selenium-core/scripts/htmlutils.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/selenium-core/scripts/atoms.js"/></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/selenium-core/scripts/selenium-browserbot.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/jsunit/app/jsUnitCore.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/preferences.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/tools.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/file-utils.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/options.js"></script>
		<script type="text/javascript" src="chrome://selenium-ide/content/storedHistory.js"></script>
		<script type="text/javascript" src="testHelper.js"></script>
		<script type="text/javascript">
function setUp() {
    window.storedHistory = new StoredHistory("testStoredHistory", 5);
    storedHistory.clear();
}

function testShouldKeepMaxItems() {
    storedHistory.add("t1");
    storedHistory.add("t2");
    storedHistory.add("t3");
    storedHistory.add("t4");
    storedHistory.add("t5");
    storedHistory.add("t6");
    assertArrayEquals(["t6","t5","t4","t3","t2"], storedHistory.list());
}

function testEmptyList() {
    assertArrayEquals([], storedHistory.list());
}

function testAdd() {
    this.storedHistory.add("/tmp/foobar");
    assertArrayEquals(["/tmp/foobar"], this.storedHistory.list());
    this.storedHistory.add("/tmp/foobarbaz");
    assertArrayEquals(["/tmp/foobarbaz", "/tmp/foobar"], this.storedHistory.list());
}

function testAddDuplicateItemAndMakeThemUnique() {
    this.storedHistory.add("/tmp/foobar");
    this.storedHistory.add("/tmp/foobarbaz");
    this.storedHistory.add("/tmp/foobar");
    assertArrayEquals(["/tmp/foobar", "/tmp/foobarbaz"], this.storedHistory.list());
}

function nativePath(path) {
    if (navigator.platform.match(/^Win/)) {
        return "C:" + path.replace(/\//g, '\\');
    } else {
        return path;
    }
}

function testShouldMapMenuItem() {
    this.storedHistory.add(nativePath("/tmp/foobar.txt"));
    this.storedHistory.add(nativePath("/baz"));
    var list = [];
    this.storedHistory.mapMenuItem(function(item) {
	list.push(item);
    });
    assertArrayEquals([
        {label: "baz []", value: nativePath("/baz")},
        {label: "foobar.txt [tmp]", value: nativePath("/tmp/foobar.txt")}
    ],
		      list);
}

</script>
  </head>

  <body>
  </body>
</html>
